﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CreditAgricole.Framework;
using System.Web.UI.WebControls;
using Microsoft.Office.Server.Search.Administration;
using Microsoft.SharePoint;
using Microsoft.Office.Server.Search.Query;

namespace CreditAgricole.PageCodeBehind
{
    public partial class Site: System.Web.UI.MasterPage, IMasterPage
    {
        protected SiteMenu MainSiteMenu;
        protected TextBox txt_search;
        protected ImageButton butt_search;
        protected DropDownList ddlScopes;

        public void SelectMenuItem(Constants.ElementsSiteMenu oMenuItem)
        {
            MainSiteMenu.SelectMenuItem(oMenuItem);
        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (!this.Page.IsPostBack)
            {
                ScopeInformation[] allScopes = null;
                using (KeywordQuery keywordQuery = new KeywordQuery(SPContext.Current.Site))
                {
                    allScopes = keywordQuery.GetScopes();
                };
                ddlScopes.DataSource = allScopes;
                ddlScopes.DataTextField = "Name";
                ddlScopes.SelectedIndex = 1;
                ddlScopes.DataBind();
            }
            butt_search.Click += new System.Web.UI.ImageClickEventHandler(OnSearchGo);
        }

        protected void OnSearchGo(object sender, EventArgs args)
        {
            if (!txt_search.Text.Contains("recherche dans"))
            {
                Response.Redirect(string.Format("Search.aspx?k={0}&s={1}", txt_search.Text, ddlScopes.SelectedItem.Text));
            }
        }
    }
}
